
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link href="../css/main.css" type="text/css" rel="stylesheet" />
		<link href="../css/dialog.css" rel="stylesheet" type="text/css">
		
		<link rel="stylesheet" href="../css/zTreeStyle/zTreeStyle.css" type="text/css">
		<title></title>
		<style type="text/css">
			textarea{width: 260px;height: 100px;border: #a6d9da solid 1px;padding: 5px;}
		</style>
	</head>
	<body>
		<div class="main_frame">
			<div class="position_div">
				<img src="../images/position_icon.png" />
				<i>消息中心</i><i>&gt;&gt;</i><i>消息推送</i>
			</div>
			<div class="right_div">
				<div class="search_div">					
					
					<div class="label_div">
						<label class="text_label">标题：</label>
						<input type="text" class="input_search" placeholder="" id="qry_device_name" />
					</div>
					<!-- <div class="label_div">
						<label class="text_label">故障编号：</label>
						<input type="text" class="input_search" placeholder="" id="qry_name" />
					</div> -->
		
					
					<div class="done_div">
						<button class="btn_common1 title_div2"  onclick="qryItemListBtn()">
							<i></i>搜索
						</button>
						<button style="margin-left:10px !important" class="btn_common2 newadd"   onclick="toAddForm()">
							<i></i>新增
						</button>
					</div>
                    <div class="cl">&nbsp;</div>
				</div>
				<table class="table_list">
					<tr>
						<th width="5%">序号</th>
						<th width="15%">标题</th>
						<th width="10%">类型</th>
						<th width="25%">内容</th>
						
						<th width="25%">接收人</th>
						<th width="10%">状态</th>
						<th class="last_td">操作</th>
					</tr>
					<tbody id="listbox1">
					</tbody>
				</table>
				<div class="turn_page" style="display:none">
				   <div class="main_page" id="pageCon">
					   <a href="javascript:void(0)" class="first_a" id="firstPage"></a>
					   <a href="javascript:void(0)" class="up_a" id="prev"></a>    	
					   <a href="javascript:void(0)" class="next_a" id="next"></a>
					   <a href="javascript:void(0)" class="last_a" id="lastPage"></a>
					   <input id="page_num_input" style="width:40px;" type="text" onblur="checkValue(this);" onkeyup="value=value.replace(/\D/g,'')"/>
					   <button type="button" class="num_input" id="go_num_input">跳转</button>
					   <b class="page_text">当前<i><em id="nowpage"></em>/<em id="totalpage"></em></i>页，总数<i id="totalNum"></i>条</b>    	
				   </div>
				</div>
				
				
				
				
				 <div class="right_content_edit" >
				 <form action="" id="form">
				    <div class="blank_div"></div>
				    <label class="text_label label_width">标题：</label>
				    <input type="text" class="input_search width_input" name ="title"/>
				     &nbsp;&nbsp;<span style="color: red">*</span>
				     <div class="blank_div"></div>
					<label class="text_label label_width">消息类型：</label>
					<div class="drop_frame">
						<i class="text_i notNull" data-status="" >显示状态</i><span
							class="span_arrow"></span>
							<ul class="choose_ul">
							<li><a href="javascript:void(0)" class="choose_a" data-status="1">广告</a></li>
							<li><a href="javascript:void(0)" class="choose_a" data-status="2">通知</a></li>
							<li><a href="javascript:void(0)" class="choose_a" data-status="3">服务</a></li>
							</ul>
							<input type = "hidden" name ="type">
					</div>
					&nbsp;&nbsp;<span style="color: red">*</span>

					<div class="blank_div"></div>
					<label class="text_label label_width">消息内容：</label>
					<textarea class="textarea notNull" name="content" data-maxLen="200"></textarea>
					&nbsp;&nbsp;<span style="color: red">* 200字以内</span>
					<div class="blank_div"></div>
				    <label class="text_label label_width">接收人：</label>
				    <div class="content_wrap">
						<ul id="treeDemo" class="ztree"></ul>
					</div>
					<input type = "hidden" name ="receiveIds" class="notNull" data-name="接收人">
					</form>
					<div class="blank_div"></div>
					<div class="blank_div"></div>
			    	<div class="bottom_donebtn width_div">
			    		<button class="btn_common2" onclick="itemFormSubmit()">提交</button>
			    		<button class="btn_common1" onclick="edit_cancel(1)">取消</button>
			    	</div>
			  	</div>
				
				
				
				
			</div>
		</div>
		
		<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/dialog.js"></script>
		<script type="text/javascript" src="../js/jquery-data.js"></script>
		<script type="text/javascript" src="../js/jquery.ztree.core-3.5.js"></script>
		<script type="text/javascript" src="../js/jquery.ztree.excheck-3.5.js"></script>
		<script type="text/javascript">
			var yema=1;
			var pagelen=10;
			var totalPage=0;   
			var setting = {
					check: {
						enable: true
					},
					data: {
						simpleData: {
							enable: true
						}
					}
				};

			function qryList(){		
				qryItemList();
			}
			
			$(document).ready(function(){
				getReceiverList();
				qryList();
			});
			

			function qryList(){
				qryItemList();
			}
			function qryItemListBtn(){
				 yema=1;
				qryItemList();
			}
			function qryItemList(){
				$.ajax({
					url: 'qryPushMsgList', 
					type: 'POST',
					data:{repairNo:$("#qry_name").val(),
						deviceName:$("#qry_device_name").val(),
						
						yema:yema,length:pagelen},
					async: false,
					dataType: 'json', 
					timeout: 10000, 
					error: function(){LQWarn('请求失败,请稍后重试');}, 
					success: function(result){
						
						if(result.resultCode==1000){
							var items=result.returnObject.pageList;
							if (items && items.length > 0) {
								var rlist="";
								var item ;
								
								$.each(items,function(i){
									item = items[i];
									rlist+='<tr data-status ="'+ item.id+'"><td>'
										+ (i+1+length*(result.returnObject.curPage-1))
										+ '</td><td>' 
										+ item.title
										+ '</td><td>' /* 
										//+ (item.status == 1?"待派单":item.status == 2?"已派单" :"已完成")
										+ '</td><td> */
										+ (item.type == 1?"广告":item.type == 2?"通知" :"服务")
										+ '</td><td>' 
										+ replaceNull(item.content)
										+ '</td><td>' 
										+ replaceNull(item.receiveName)
										+'</td><td>'
										+ (item.status == 1?"未发送":"已发送")
										
										//+ formatToDateTime(item.createTime)
										+'</td><td class="last_td">';
										if(item.status == 1){
											
											rlist += '<a class="del" title="删除" href="javascript:void(0);" onclick="delItem(this)">删除</a>'
												//+ '<a class="see" title="推送" href="javascript:void(0);" onclick="toWork(this)" >推送</a>'
										
										}
										
										rlist += '</td></tr>';
								});
								$("#listbox1").html(rlist);
								totalPage=result.returnObject.totalPage;
								$("#nowpage").html(result.returnObject.curPage);
								$("#totalpage").html(totalPage);
								$("#totalNum").html(result.returnObject.totalNum);
								$(".turn_page").show();
							}else{
								$("#listbox1").html("");
								$(".turn_page").hide();
							}
						}
						else if(result.resultCode==1004){
							LQWarn(result.returnObject);
							window.top.location.href ="../login.jsp";
						}else{
							LQWarn(result.returnObject);
						}
					}
				});
			}
			
			var url_ = "addPushMessages.do";
			var show = false;
			function toAddForm(){
				$(".right_content_edit").show();
				if($(".turn_page").is(':visible')){
					show = true;
				}
				$(".search_div,.turn_page,.table_list").hide();
				$("#form").clearForm();
				
			}

			
			function itemFormSubmit(){
			//	console.log($("#form").serialize());
				
				var menus=[];
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var checked = treeObj.getCheckedNodes(true);
				$.each(checked,function(i){
					if(!checked[i].isParent)
					//var id=checked[i].id;
					menus.push(checked[i].id);
				});
				console.log();
				$("input[name='receiveIds']").val(menus.join(","));
				if($("#form").checkhaveNull()){
					return;
				}
				var obj = $("#form").serialize();
				//obj.receiveIds = menus.join(",")
				console.log(obj);
				operateObject(url_,$("#form").serialize(),function(){edit_cancel();});
				//return;
				
			}
			
			
		
			function delItem(obj){
				
				var id = $(obj).parents("tr").attr("data-status");
				delObject('delMsg.do',{"id":id});
				
				
			}
			
			function edit_cancel(){
				$(".right_content_edit").hide();
				$(".search_div,.turn_page,.table_list").show();
				if(!show) $(".turn_page").hide();
			}
			
			
		function getReceiverList(){
			var result  = common_ajax('getReceiverList');
			var zNodes = [];
			for ( var i = 0;i<  result.length ;i++) { 
				var node_={};
				node_.id= result[i].id
				node_.name = result[i].name
				node_.pId= result[i].dealerId;
				node_.open=true;
				//node_.icon = "../images/unbound-tree-icon.png";
				zNodes.push(node_);

			}
			//console.log(zNodes);
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		}	
		
		</script>
	</body>
</html>
